<?php

class Module_Input {


	function __construct() { /* EMTPTY */ }
	
	function esc( $var ) {
		
		if ( is_array($var) ) {
			foreach( $var as $key => $value )
				$var[$key] = $this->esc($value);
			return $var;
		}
		else return stripslashes($var);
		
	}
	
	function post( $name, $def = null ) {
		if ( !isset($_POST[$name]) ) return $def;
		if ( get_magic_quotes_gpc() ) return $this->esc($_POST[$name]);
		else return $_POST[$name];
	}
	function get( $name, $def = null  ) {
		if ( !isset($_GET[$name]) ) return $def;
		if ( get_magic_quotes_gpc() ) return $this->esc($_GET[$name]);
		else return $_GET[$name];
	}
	
	function post_exists( $name = null ) {
		$ret = false;
		if ( is_null($name) ) {
			if ( isset($_POST) && count($_POST) != 0 ) $ret = true;
		}
		else {
			if ( isset($_POST[$name]) && $_POST[$name] !== "" ) $ret = true;
		}
		return $ret;
	}
	function get_exists( $name = null ) {
		$ret = false;
		if ( is_null($name) ) {
			if ( isset($_GET) && count($_GET) != 0 ) $ret = true;
		}
		else {
			if ( isset($_GET[$name])  && $_GET[$name] !== "" ) $ret = true;
		}
		return $ret;
	}
	function files_exists( $name = null ) {
		$ret = false;

		if ( is_null($name) ) {
			foreach($_FILES as $k => $v) {
				if ( $v['error'] == 0 ) $ret = true;;
			}
		}
		else {
			if ( isset($_FILES[$name])  && $_FILES[$name] !== "" && $_FILES[$name]['error'] == 0) $ret = true;
		}
		return $ret;
	}
}